from framwork.common.tools  import open_browsers
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

"""自定义条件搜索客户  ok"""
#数据
url=r"http://192.168.1.36/crm/index.php?m=user&a=login"
user_name="admin"
passwd="123456"
select1="客户名称"
select2="包含"
input="经纬达"

#定位器
username_locator=(By.NAME,"name")
password_locator=(By.NAME,"password")
login_btn_locator=(By.NAME,"submit")
customer_locator=(By.LINK_TEXT,"客户")
select1_locator=(By.CSS_SELECTOR,"#field")
select2_locator=(By.CSS_SELECTOR,"#condition")
input_locator=(By.CSS_SELECTOR,"#search")
search_locator=(By.CSS_SELECTOR,"#dosearch")
#操作
driver=open_browsers()
driver.get(url)
sleep(3)
driver.find_element(*username_locator).send_keys(user_name)
driver.find_element(*password_locator).send_keys(passwd)
driver.find_element(*login_btn_locator).click()
sleep(1)
driver.find_element(*customer_locator).click()
s1=driver.find_element(*select1_locator)
s1_obj=Select(s1)
s1_obj.select_by_visible_text(select1)
s2=driver.find_element(*select2_locator)
s2_obj=Select(s2)
s2_obj.select_by_visible_text(select2)
driver.find_element(*input_locator).send_keys(input)
driver.find_element(*search_locator).click()
sleep(1)
#退出浏览器
sleep(3)
driver.close()